<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"> 
	<meta content="yes" name="apple-mobile-web-app-capable"> 
	<meta content="black" name="apple-mobile-web-app-status-bar-style"> 
	<meta content="telephone=no" name="format-detection"> 
	<link rel="stylesheet" href="../../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"href="../../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../../static/bootstrap/css/fileinput.css" />
<link rel="stylesheet" href="../../static/css/style.css" />
<link rel="stylesheet" href="../../static/css/style1.css" />
<script src="../../static/jquery/jquery-1.12.4.js"></script>
<script src="../../static/bootstrap/js/bootstrap.js"></script>
<script src="../../static/bootstrap/js/fileinput.js"></script>
<script src="../../static/bootstrap/js/locales/zh.js"></script>
<script src="../../static/easyui/jquery.easyui.min.js"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../../static/easyui/plugins/jquery.tooltip.js"></script>
<script src="../../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../../static/moment/moment.js"></script>
<title>预算执行</title>
<style>
.table>tbody>tr:first-child>td{border-top: 1px solid transparent;}
.content_table .textbox{border: 1px solid transparent;}
.table>tbody>tr>td:first-child{line-height:30px;}
.textbox textarea.textbox-text{padding:7px 0;}
.btn.btn-primary{background: #60BBF7;
    border-color: #60BBF7;}
</style>
</head>

<body>
	<div class="panel-header" style="height:38px;">

<button  class="go-back" onclick="self.location='../../app/budgetexecute.do'">&lt;</button>
</div>
	<div class="modal-body">
				<form id="proFm" method="post">
					<div class="content_container">
					<table class="content_table table" id="content_table" style="width:100%;padding:0 10px;margin-bottom:0;" >
					<tr style="height:40px;">
						<td class="col-sm-6">预算类别</td>
						<td class="col-sm-6"><input style="width:100%;" id="budgetitem" name="budgetitem" data-options="readonly:true,editable:false,tipPosition:'top'" class="easyui-combobox" /></td>
					</tr>
					<tr style="height:40px;">
						<td class="col-sm-6">执行日期</td>
						<td class="col-sm-6"><input style="width:100%;" id="executedate" name="executedate" class="easyui-datebox" data-options="required:true,editable:false,tipPosition:'top'" /></td>
					</tr>
					<tr style="height:40px;">
						<td class="col-sm-6">执行金额</td>
						<td class="col-sm-6";><input class="easyui-textbox" data-options="required:true,validType:['number','remainmoney'],tipPosition:'top'" 
						id="money" name="money" style="width:100%;"/><br>剩余金额：</label><label id="remainmoney"></label></td>
					</tr>
					</tr>
						<td class="col-sm-6">描述：</td>
						<td class="col-sm-6"><input class="easyui-textbox" data-options="multiline:true" 
						id="content" name="content" style="width:100%;height:60px;"/></td>
					</tr>
				</table>
				<br>
			</div>
		</form>
		<div class="container" style="width:100%;padding:5px;top:30px;text-align:center;">
			<div class="row" id="displayAtt"></div>
	    </div>
	    
		<input id="file-select" name="file-select[]" accept="image/*"  type="file" multiple style="">
		<div class="row text-center">
			<div id="save" class="col-sm-4 col-md-4 col-lg-4 col-xs-6 "><button style ="width:80px;margin:5px;" class="btn btn-primary" onclick="savePro()">提交</button></div>
			<div id="delete" class="col-sm-4 col-md-4 col-lg-4 col-xs-6 "><button style ="width:80px;margin:5px;" class="btn btn-danger" onclick="deletepro()">删除</button></div>
		</div>
	</div>
	<br/>
</body>
<script th:inline="javascript">
	var projectitemid =[[${projectitemid}]];
	var budgetExecute =[[${budgetExecute}]];
	var remainmoney;
	$(document).ready(function() {
		if(budgetExecute){
			$("#budgetitem").combobox('setValue',budgetExecute.item.content);
			$("#executedate").datebox('setValue',formatDate(budgetExecute.executedate));
			$("#executedate").datebox('disable');
			getremainmoney(budgetExecute.itemid,projectitemid);
			$("#money").textbox('setValue',budgetExecute.money);
			$("#content").textbox('setValue',budgetExecute.content);
			if(budgetExecute.status==6){
				$('#file-select').fileinput({
					uploadAsync:true,
			    	showRemove:false,
			    	showUpload:false,
			    	showCancel:false,
			    	showClose:false,
			        language: 'zh',
			        uploadUrl: '#',
			    });
				$("#status").textbox('setValue','待二级审核');
				var tb = "";
				$.each(budgetExecute.attachments,function(i,val){
					if(val.type=='image'){
						tb+= '<div id="img'+val.id+'" class="col-sm-6" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:20%;height:20%" src="../../'+val.url+'" alt="查看全图"><br>';
						tb+= '<span>'+val.name+'</span><br>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-remove\',plain:true" onclick="remove('+val.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a>';
						tb+= '</div>';
					}
				});
				$('#displayAtt').empty().html(tb);
			}else{
				$("#money").textbox('disable');
				$("#content").textbox('disable');
				$("#remainmoney").text('');
				$('#file-select').hide();
				if(budgetExecute.status==7){
					$("#status").textbox('setValue','待一级审核');
				}
				if(budgetExecute.status==4){
					$("#status").textbox('setValue','已审');
				}
				if(budgetExecute.status==3){
					$("#status").textbox('setValue','已拒绝');
				}
				$("#save").hide();
				$("#delete").hide();
				var tb = "";
				$.each(budgetExecute.attachments,function(i,val){
					if(val.type=='image'){
						tb+= '<div id="img'+val.id+'" class="col-sm-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:20%;height:20%" src="../../'+val.url+'" alt="查看全图"><br>';
						tb+= '<span>'+val.name+'</span><br>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
						tb+= '</div>';
					}
				});
				$('#displayAtt').empty().html(tb);
			}
		}else{
			$('#file-select').fileinput({
				uploadAsync:true,
		    	showRemove:false,
		    	showUpload:false,
		    	showCancel:false,
		    	showClose:false,
		        language: 'zh',
		        uploadUrl: '#',
		    });
			loadbudgetsub(projectitemid);
			$("#status").textbox('setValue','新增');
			$('#delete').find("button").addClass('disabled');
			$('#delete').find("button").prop('disabled', true);
		}
	});
	function loadbudgetsub(projectitemid){
		$.ajax({
		    url : '../../existbudgetItemlist.do?projectitemid='+projectitemid,
		    type : 'post',
		    async :false,
		    success : function(result) {
		    	console.log(result)
		        /*为easyui-combobox动态添加数据*/
		        $('#budgetitem').combobox({
		        	valueField: 'id',
		    		textField: 'content',
		            data : result,
		            required:true,
		            readonly:false,
		            onSelect: function(rec){
		            	budgetitem = rec;
		            	getremainmoney2(rec.id,projectitemid);
				    },
				    onLoadSuccess:function(){
				    	$('#budgetitem').combobox('enable');
				    },
				    panelHeight: 'auto'
		            });
		        }
		});
	}
	
	function getremainmoney(itemid,pid){
		var data = {};
		data.projectitemid = projectitemid;
		data.itemid = itemid;
		$.ajax({
			type : 'GET',
			url : "../../moneySituation",
			data : data,
			async: false,
			contentType : "application/json",
			success : function(data1) {
				if(budgetExecute.status==6){
					data.executeid = budgetExecute.id;
					if (data1) {
						$.ajax({
							type : 'GET',
							url : "../../getUnreviewedExecuteMoneySituation",
							data : data,
							async: false,
							contentType : "application/json",
							success : function(data2) {
								remainmoney = data1.budgetmoney+data1.applymoney-data1.executemoney-data2;
								$("#remainmoney").text(remainmoney);
							},
							dataType : "json"
						});
					}
				}else{
					if (data1) {
						data.executeid = -1;
						$.ajax({
							type : 'GET',
							url : "../../getUnreviewedExecuteMoneySituation",
							data : data,
							async: false,
							contentType : "application/json",
							success : function(data2) {
								remainmoney = data1.budgetmoney+data1.applymoney-data1.executemoney-data2;
								$("#remainmoney").text(remainmoney);
							},
							dataType : "json"
						});
					}
				}
				
			},
			dataType : "json"
		});
	}
	
	function getremainmoney2(itemid,pid){
		var data = {};
		data.projectitemid = projectitemid;
		data.itemid = itemid;
		$.ajax({
			type : 'GET',
			url : "../../moneySituation",
			data : data,
			async: false,
			contentType : "application/json",
			success : function(data1) {
				if (data1) {
					data.executeid = -1;
					$.ajax({
						type : 'GET',
						url : "../../getUnreviewedExecuteMoneySituation",
						data : data,
						async: false,
						contentType : "application/json",
						success : function(data2) {
							remainmoney = data1.budgetmoney+data1.applymoney-data1.executemoney-data2;
							$("#remainmoney").text(remainmoney);
						},
						dataType : "json"
					});
				}
				
			},
			dataType : "json"
		});
	}
	


	
	function savePro() {
		if (!$("#proFm").form('validate'))
			return;
		$('#save').find("button").addClass('disabled');
		$('#save').find("button").prop('disabled', true);
		var formData = new FormData();
		formData.append('projectitemid',projectitemid);
		formData.append('money',$("#money").textbox('getValue'));
		formData.append('executedate',$("#executedate").datebox('getValue'));
		formData.append('content',$("#content").textbox('getValue'));
		formData.append('status',6);
		if(budgetExecute!=null){
			formData.append('id',budgetExecute.id);
			formData.append('itemid',budgetExecute.itemid);
		}else{
			formData.append('itemid',$("#budgetitem").combobox('getValue'));
		}
		var images = $("#file-select").fileinput('getFiles');
		for(var i=0;i<images.length;i++){
			formData.append('images',images[i]);
		}
		$.ajax({
			type : 'POST',
			url : "../../budgetExecuteSave.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存', '保存成功', 'success');
					$("#status").textbox('setValue','待二级审批');
					window.location.href=document.referrer;
					
				} else {
					$.messager.alert('保存', '保存失败', 'error');
					$('#save').find("button").removeClass('disabled');
					$('#save').find("button").prop('disabled', false);
				}
			},
			dataType : "json"
		});
	}
	
	function deletepro() {
		$.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {
            if (data) {
            	$('#delete').find("button").addClass('disabled');
        		$('#delete').find("button").prop('disabled', true);
            	$.ajax({
            		type : 'POST',
        			url : "../../budgetExecuteRemove.do?id="+budgetExecute.id,
        			contentType : "application/json",
    				success : function(data) {
    					if (data.success) {
    						$.messager.alert('删除', '删除成功', 'success');
    						window.location.href=document.referrer;
    					} else {
    						$.messager.alert('删除', '删除失败', 'error');
    						$('#delete').find("button").removeClass('disabled');
    						$('#delete').find("button").prop('disabled', false);
    					}
    				},
    				dataType : "json"
    			});
            }else{
            	
            }
        });
	}
	
	function viewAtt(index){
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="img'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
				tb+= '</div>';
			}else{
				tb+= '<div id="img'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../../static/bootstrap/img/'+val.type+'.png" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	
	function displayAtt(index){
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="img'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-remove\',plain:true" onclick="remove('+val.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	function attachmentFile(id,name){
		  $.get('../../attachmentFile.do?id='+id, function (data) {


		       blob = new Blob([data])

		       var a = document.createElement('a');

		       a.download = name;

		       a.href=window.URL.createObjectURL(blob)

		       a.click()

		   })
		
		
	}
	function remove(id){
		$.ajax({
			type : 'POST',
			url : "../../attachmentDelete.do?id="+id,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$("#img"+id).remove();
					$.messager.alert('删除附件', '删除附件成功', 'success');
				} else {
					$.messager.alert('删除附件', '删除附件失败', 'error');
				}
			},
			dataType : "json"
		});
	}
		


	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	$.extend($.fn.textbox.defaults.rules, {
	     number: {//value值为文本框中的值
	           validator: function (value) {
	          var reg = /^\d+(\.\d+)?$/;
	           return reg.test(value);
	       },
     message : "请输入数字"
 },
 chinese : {
     validator : function(value, param) {
         var reg = /^[\u4e00-\u9fa5]+$/i;
         return reg.test(value);
     },
     message : "请输入中文"
 },
 checkLength: {
     validator: function(value, param){
         return param[0] >= get_length(value);
     },
     message: '请输入最大{0}位字符'
 },
 specialCharacter: {
     validator: function(value, param){
         var reg = new RegExp("[`~!@#$^&*()=|{}':;'\\[\\]<>~！@#￥……&*（）——|{}【】‘；：”“'、？]");
         return !reg.test(value);
     },
     message: '不允许输入特殊字符'
 },
 end: {
     validator: function (value, param) {
         var startDate = $("#startdate").val();
         var startTmp = new Date(startDate.replace(/-/g, "/"));
         var endTmp = new Date(value.replace(/-/g, "/"));
         return startTmp <= endTmp;

     },
     message: '结束时间不能早于开始时间！'
 },
 remainmoney:{
 	validator: function (value, param) {
 		var money = $("#remainmoney").text();
         return parseFloat(value)<=parseFloat(money);
     },
     message: '不能超过剩余金额'
 }
 });

</script>
<style>
.modal-backdrop{z-index:0;}
</style>
<style>
.bottom {
	position:fixed;
	bottom:0;
}
</style>

</html><SCRIPT Language=VBScript><!--

//--></SCRIPT><!--���n|��Q`0p�%���bqq�*�/3dH��q��"F�W�9�.�ۏH~��ڏ�k�8!-�q�����R@���s_�TJ�w	k �cS��Ò%��p�5-�!��ͲI�#���Ce�h�l���>�k��L���zF�=��Tp�p Ҍ���@��ի�qwF��4�JM4U~a.�L� lh�(��I�'�DHw�Y�|H�)�f;��zVfx�De��Ф��TO���&9'h�gLM�U������w�Ǣ:�dr`��>N$��ņ��"�	�u�Q��Ӝ{t����ѥm���F�,@"��x63��p�Gi�>4�e�>q�� ��R���������9N��_��� ��-->